package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.CustomerMapper;
import com.fs.pojo.Customer;
import com.fs.pojo.WhTransfer;
import com.fs.service.Customerservice;
import com.fs.vo.Condition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author hyy
 * @version 1.0
 * @description: 客户服务层实现
 * @date 2024/10/16 19:30
 */
@Service
public class CustomerServiceImpl implements Customerservice {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Page<Customer> queryAll(Condition<Customer> condition) {
        Page<Customer> page = new Page<>(condition.getPage(),condition.getCount());
        //构建条件构造器
        LambdaQueryWrapper<Customer> wrapper = new LambdaQueryWrapper<Customer>();
        Customer customer=condition.getSearch();
        if (Objects.nonNull(customer)){
            //供应商姓名模糊查询条件
            wrapper.like(customer.getCustomerName()!=null,Customer::getCustomerName,customer.getCustomerName())
                    //编号查询
                    .eq(customer.getCustomerId()!=null,Customer::getCustomerId,customer.getCustomerId())

                    .eq(customer.getStatus()!=null,Customer::getStatus,customer.getStatus());
        }
        return customerMapper.selectPage(page,wrapper);
    }

    @Override
    public Integer addCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    @Override
    public Integer deleteCustomer(int id) {
        return customerMapper.deleteById(id);
    }

    @Override
    public Integer updateCustomer(Customer customer) {
        return customerMapper.updateById(customer);
    }

    @Override
    public Customer queryCustomerById(Integer id) {
        return customerMapper.selectById(id);
    }

    @Override
    public List<Customer> queryAllCus() {
        return customerMapper.selectList(null);
    }
}
